﻿using CRM.Admin.Contracts.Contract.Customer;
using CRM.Admin.Contracts.Dto.Customer;
using CRM.Admin.Contracts.Model.Customer;
using KingsSharp.Common;
using KingsSharp.Core;
using KingsSharp.Core.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CRM.Admin.Services.Service.Customer
{
    public class VarietyYearService : ServiceBase, IVarietyYearService
    {

        private IRepository<VarietyYear, Guid> VarietyYearRepository;
        public VarietyYearService(IRepository<VarietyYear, Guid> _VarietyYearRepository)
             : base(_VarietyYearRepository.UnitOfWork)
        {
            VarietyYearRepository = _VarietyYearRepository;
        }
        public IQueryable<VarietyYear> VarietyYears
        {
            get { return VarietyYearRepository.Entities; }
        }

        public KingsSharp.Common.Data.OperationResult Insert(params VarietyYearDto[] dtos)
        {
            dtos.CheckNotNull("dtos");
            foreach (var t in dtos)
            {
                t.Id = Guid.NewGuid();
            }
            var result = VarietyYearRepository.Insert(dtos);
            return result;
        }

        public KingsSharp.Common.Data.OperationResult Update(params VarietyYearDto[] dtos)
        {
            dtos.CheckNotNull("dtos");
            var result = VarietyYearRepository.Update(dtos);
            return result;
        }

        public KingsSharp.Common.Data.OperationResult Delete(params Guid[] ids)
        {
            var entitys = VarietyYearRepository.Entities.Where(a => ids.Contains(a.Id)).ToList();
            entitys.ForEach(a => a.IsDeleted = true);
            int result = VarietyYearRepository.Update(entitys.ToArray());
            return new KingsSharp.Common.Data.OperationResult(KingsSharp.Common.Data.OperationResultType.Success, "删除成功");
        }
    }
}
